package cn.imu.appdevexperiment2020.cch.cchactivity;

import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;
import cn.imu.appdevexperiment2020.R;
import cn.imu.appdevexperiment2020.cch.retrofit.api.ApiClient;
import cn.imu.appdevexperiment2020.cch.retrofit.bean.RegisterResultBean;
import cn.imu.appdevexperiment2020.cch.retrofit.bean.RegisterSendBean;
import cn.imu.appdevexperiment2020.cch.util.AuthUtil;
import cn.imu.appdevexperiment2020.cch.util.ToastUtil;
import cn.imu.appdevexperiment2020.common.BaseActivity;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * 描述:
 *
 * @author chenconghua
 * @version 1.0
 * @create 2022-11-04 01:38
 */
public class RetrofitTestActivity extends BaseActivity {

   @BindView(R.id.tv_retrofittest_content)
    TextView content;
   @Override
   protected void onCreate(@Nullable Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.cch_activity_retrofittest);

   }

   @OnClick(R.id.btn_retrofittest_test)
   public void test(){

      RegisterSendBean registerSendBean=new RegisterSendBean();
      registerSendBean.setUserName("c11");
      registerSendBean.setPassword("123456");
      registerSendBean.setNickName("cc1");
      registerSendBean.setClassesId("110");
      registerSendBean.setEmail("c1c11@163.com");
      registerSendBean.setPhonenumber("17381356761");
      registerSendBean.setSex("0");
      registerSendBean.setStatus("0");



      Call<RegisterResultBean> call = ApiClient.getInstance(getApplicationContext()).getReturnData(AuthUtil.GetAuth(),registerSendBean);
      call.enqueue(new Callback<RegisterResultBean>() {
         @Override
         public void onResponse(Call<RegisterResultBean> call, Response<RegisterResultBean> response) {
            if (response.body()!=null){
               if (response.body().getCode()==200){
                  content.setText(response.body().getMsg().toString());
               }else {
                  ToastUtil.ShowToast(getApplicationContext(),"111");
               }
            }else{
               ToastUtil.ShowToast(getApplicationContext(),"网络错误");
            }
         }

         @Override
         public void onFailure(Call<RegisterResultBean> call, Throwable t) {
            ToastUtil.ShowToast(getApplicationContext(), "网络请求错误111");
         }
      });


   }
}
